import Vue from 'vue'
import vuex from 'vuex'

Vue.use(vuex);

export default new vuex.Store({
  state: {
    music: {               //当前播放音乐具体信息
      mid:"",              
      name:"",
      artists:[],
      ablumName:"",
      ablumPic:"",
      musicUrl:""
    },
    isMusic: false, //是否播放音乐
    findHeadIndex: 0,  //首页导航条当前索引
    musicList: {},   //当前打开的歌单信息
    isMusicList: false,   //歌单是否打开
    isOpenPlayMusic:false
  },
  getters: {

  },
  mutations: {
    addsong(state, song) {  //添加音乐到队列中
      state.music = song
    },
    addMusicUrl(state, url) {            //添加异步获取到的音乐链接
      Vue.set(state.music, 'musicUrl', url)
    },
    play(state) {  //音乐播放中
      state.isMusic = true;
    },
    pause(state) {  //音乐暂停中
      state.isMusic = false;
    },
    findHeadIndex(state, X) {  //添加导航索引
      state.findHeadIndex = X;
    },
    openMusicList(state, listInfo) {  //存储当前歌单信息
      state.musicList = listInfo;
    },
    isMusicList(state, status) {  //存储当前歌单信息
      state.isMusicList = status;
    }
  },
  actions: {
    getSongUrl(context, id) {
      Vue.http.get('http://localhost:3000/music/url?id=' + id)
        .then(response => {
          console.log(response.body.data[0].url)
          context.commit('addMusicUrl', response.body.data[0].url)
        })
    }
  }
})
